#pragma once
#include "gl/context.hh"

struct fps_counter
{
	using value_type = int;
	using value_ref  = value_type&;
	using context_cref = gl::context const&;
	using ms_type = gl::context::millisecond_type;

	fps_counter(value_ref result, context_cref ctx)
		: result{result}, ctx{ctx}, start{ctx.tick()} {}
	~fps_counter()
	{
		auto mspf = ctx.tick() - start;
		if (mspf) result = 1000 / mspf;
	}

private:
	value_ref result;
	context_cref ctx;
	ms_type start;
};

